package com.mall.product.controller;

import com.mall.common.entity.Result;
import com.mall.product.entity.vo.CategoryTreeNodeVO;
import com.mall.product.service.ProductCategoryService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequiredArgsConstructor
@RequestMapping("/api/category")
@Tag(name = "商品分类")
public class ProductCategoryController {

    private final ProductCategoryService productCategoryService;

    @GetMapping("/tree")
    @Operation(summary = "商品分类树")
    public Result<List<CategoryTreeNodeVO>> getCategoryTree() {
        try {
            List<CategoryTreeNodeVO> tree = productCategoryService.getCategoryTree();
            return Result.success(tree);
        } catch (Exception e) {
            return Result.error("获取分类树失败");
        }
    }
}